<?php
$nome       =  trim($_POST["nome"]);
$cpf        =  trim($_POST["cpf"]);
$endereco   =  trim($_POST["endereco"]);
$telefone   =  trim($_POST["telefone"]);
$sala       =  trim($_POST["sala"]);
$horario    =  trim($_POST["horario"]);
$dia        =  $_POST["dia"];
$complemento=  trim($_POST["complemento"]);


$tes = 0;



 
include 'validarCpf.php';
require 'conexao.php';
if (empty($nome)||empty($telefone)||empty($cpf)||empty($endereco)||empty($dia)||empty($horario)||empty($sala)){
    header("location: ../view/viewErro.php?erro=1");

   
}
    if(!(isCpfValid($cpf))){
        header("location: ../view/viewErro.php?erro=3");}
    
    else{ $j=0;
			for($i=0; $i<(strlen($cpf)); $i++)
				{
					if(is_numeric($cpf[$i]))
						{
							$num[$j]=$cpf[$i];
							$j++;
						}
				}
   // $cpf = $num[];
   $cpf = (implode('', $num));
    
 $tes = mysql_query("insert into cadastroaluno (id,dia,nome,tel,endereco,cpf,sala,horario,complemento) 
     values ( '', '".$dia."','".$nome."','".$telefone."','".$endereco."','".$cpf."','".$sala."','".$horario."','".$complemento."')");

 if($tes){
 echo "<META HTTP-EQUIV=Refresh CONTENT='3; URL=../view/principal.php'>
 <center><h1>Cadasro realizado com sucesso!!!</h1></center>";}

 else{
     header("location: ../view/viewErro.php?erro=5");}
  
 }

 //mysql_free_result($tes);
 ?>
 